Incorporation into the Main Program


This explains how to link Sound Objects, output when mks4agb.exe is run, into the main program. This explanation was written for sound developers and main programmers.

* This explanation assumes that the procedures in Step 2 of this Tutorial have been followed. 

INDEX    Incorporation into the Main Program 
1.  Sound Developer Duties
2. Main Programmer Duties  "Incorporation into Games"
(1) Arranging Sound Objects
(2) Rewriting the Makefile
3. Main Programmer Duties "Calling Sound Drivers"
(1) Incorporating Header Files
(2) Initialization
(3) What should happen immediately after each V Blank Interrupt
(4) What should happen during each V Blank Interrupt(Every 1/60sec.)
(5) Example: Start Playing Song Number 14
(Reference)Example: Using Sound Driver Functions with the Demo.

1. Sound Developer Duties

Turn over to the Main Programmer, all files output to the out_dir  that are specified in the mks4agb.ini file. The relevant files are listed below. 

m4aLib.h   m4aLib.o   SoundDat.o    Soundfiles   {wavename}.o   {songname}.o

Return to Top


2. Main Programmer Duties "Incorporation into Games"

(1) Arranging Sound Objects
Make a Sound Directory in the same Directory as the Makefile of the Main Program. Copy the Sound Object Groups received from the sound developer into the Sound Directory. 

Return to Top
 

(2) Rewriting the Makefile
Add the following two lines to the beginning of the Makefile. 

SOUND_DIR = Sound/
include $(SOUND_DIR)Soundfiles

In the Soundfiles, the Sound Object Groups are defined as macros with the macro name SOUND_FILES. For this reason, in order to link the Sound Object Group to the Main Program, add the target dependent file $(TARGET_ELF) and place $(SOUND_FILES) in the command line. 
If the Makefile used in the functional_sample provided with the Game Boy Advance Developer Toolkit 2.0 were used, it would look as follows. 

$(TARGET_ELF): $(.OFILES) $(SOUND_FILES) Makefile $(DEPENDFILE)
    @echo > $(MAPFILE)
    $(CC) -g -o $@ $(.OFILES) $(SOUND_FILES) -Wl,$(LDFLAGS)


Return to Top


3. Main Programmer Duties "Calling Sound Drivers"

(1) The following declaration is made for files which have a section using a sound-related function.

#include "Relative path to Sound Directory/m4aLib.h"

For example, if it were included in the same directory as the Makefile, then it would be: 
#include "Sound/m4aLib.h" 

Return to Top
 

(2) Call the following functions with the initialization routine following a reset. 
Initialize sound-related I/O and set aside a work directory. 

m4aSoundInit( );


Return to Top
 

(3) Call the following function immediately after each V Blank Interrupt. 
The timing is critical, so it would be ideal if this could be called before any other process. 
Note: The processing itself is extremely short. 

m4aSoundVSync( );


Return to Top
 

(4) Call the following function during each V Blank Period (every 1/60 second). 
There is no need to be concerned about the timing here and it may be called after all other non-music processes have finished. 

m4aSoundMain( );


Return to Top
 

(5) Start playing Song Number 14. 
As a test, try adding the following function to the process when the A Button is pressed. If the Sound Objects used in the tutorial are linked, the Main Song in the demonstration will begin playing. 

m4aSongNumStart(14);


Return to Top
 

(Reference) Example of How to Use the Sound Driver Functions in the Demonstration
The settings (1) ~ (4) are the minimum necessary settings when using a Sound Driver. A list of examples of how the Sound Driver Functions are used follows below. (This is just one example.) 

- Start or Change the Performance Using the Song Number
Starts playing Song Number 14. 
m4aSongNumStartOrChange(14);


- Stop (Pause) the Playing of all Songs 
Stops all songs after fading them out, or other effect. 
m4aMPlayAllStop( );


- Change the Scale
Adds the value pi (semitone = 256) to Track 1 of the Song being played by Music Player Number 3.   *pi is a signed short int. 
m4aMPlayPitchControl(&m4a_mplay003,1,pi);

- Change the Position
Adds the value pa to the panpot of Track 1 of the Song being played by Music Player Number 3.   *pa is a signed char. 
m4aMPlayPanpotControl(&m4a_mplay003, 1, pa);

- Fade Out a Song
Fades out the song being played on Music Player Number i at speed 10. 
m4aMPlayFadeOut(mplay_table[i].ma, 10);


Return to Top


[ | Back | User's Manual Table of Contents | Tutorial Table of Contents | Next |]